<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('业务时间')">
              <j-date
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('开始时间')"
                class="query-group-cust"
                v-model="queryParam.bTime"
              ></j-date>
              <span class="query-group-split-cust"></span>
              <j-date
                :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('结束时间')"
                class="query-group-cust"
                v-model="queryParam.eTime"
              ></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('会员信息')">
              <a-input :placeholder="$t('请输入手机号/卡号/姓名')" v-model="queryParam.memberInfo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="9" :md="10" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('重置')}}</a-button>
              <a-button type="primary" icon="download" :loading="exloading" style="margin-left: 8px" @click="handleExportXls($t('会员消费排名'))" v-has="'MemberConsumerRankReportController:export'"
                >{{$t('导出')}}</a-button
              >
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :customHeaderRow="customHeaderRow"
        :customRow="customRow"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{$t('无图片')}}</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{$t('无文件')}}</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            {{$t('下载')}}
          </a-button>
        </template>
      </a-table>
    </div>
  </a-card>
</template>

<script>
import moment from 'moment'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'MemberConsumerRank',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  data() {
    return {
      description: '会员消费排名',
      moment,
      isorter: {
        column: 'rankNo',
        order: 'asc',
      },
      // 表头
      columns: [
        {
          title: this.$t('名次'),
          dataIndex: 'rankNo',
          width: 120,
          align: 'center',
        },
        {
          title: this.$t('手机号'),
          align: 'center',
          dataIndex: 'phone',
        },
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'cardNo',
        },
        {
          title: this.$t('姓名'),
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: this.$t('投币次数'),
          align: 'right',
          dataIndex: 'busiNum',
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('投币值'),
          align: 'center',
          dataIndex: 'coin',
          customCell: function (t, r) {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
          customRender: (text, r) => {
            text = (text ==null || text =="" || text ==undefined)?0:parseFloat(text);
            return text.toFixed(2);
          }
        },
      ],
      url: {
        list: '/report/day/memberConsumerRank/list',
        exportXlsUrl: '/report/day/memberConsumerRank/export',
      },
      dictOptions: {},
      isCustom:true,
      isHideData:false
    }
  },
  created() {},
  mounted(){
    let that=this
    document.onkeydown = function(e) {
      let key = window.event.keyCode;
      if (key== 75 && event.ctrlKey) {
        window.event.preventDefault()
        that.isHideData = false
        that.queryParam.dataType=0
        that.searchQuery()
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {
      this.customInit()
    },
    customInit() {
      this.isHideData = true
      this.queryParam.dataType=1
      this.loadData(1)
    },
    searchReset(){
      this.queryParam={}
      this.selectedRowIndex = []
      this.customInit()
    }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>